package com.example.homework.controller;

import com.example.homework.Pojo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class ListWorkTwoController{

    @GetMapping("/ListWorkTwoController/{count}")
    public Result fibonacci(@PathVariable int count) {
        if(count<0||count>100)
            return Result.error();
        List<Integer[]> fibonacciList = new ArrayList<>();

        int a = 0;
        int b = 1;

        for (int i = 0; i < count; i++) {
            Integer[] fibonacciPair = {a, b};
            fibonacciList.add(fibonacciPair);

            int temp = a + b;
            a = b;
            b = temp;
        }
        return Result.send(fibonacciList);
    }
}